<%@include file="../viewPartials/header.jsp" %>
<c:url value="Home" var="homeUrl" />

<h1>New LinkCollection</h1>
<c:choose>
    <c:when test="${param.success == 'true'}">
        <%-- Success is true (redirected after successfull post) --%>
        LinkCollection saved! <a href="${homeUrl}">Back</a>
    </c:when>
    <c:otherwise>
        
        <%-- Display form errors if necessary --%>
        <c:if test="${formErrors != null}">
            <div class="formErrors">
                <c:forEach var="errors" items="${formErrors}">
                    ${fn:escapeXml(errors.getMessage())}<br>
                </c:forEach>
            </div>
        </c:if>
        
        <form method="post" action="">
            <table class="tblForm">
                <tr>
                    <td width="100"><label for="name">Name</label></td>
                    <td><input value="${fn:escapeXml(linkCollection.name)}"
                               id="name"
                               name="name"
                               type="text"></td>
                </tr>
                <tr>
                    <td><label>Folder</label></td>
                    <td>
                        <input value="${linkCollection.parent.id}"
                               data-foldername="${fn:escapeXml(linkCollection.parent.name)}"
                               id="txtFolderId"
                               name="folderId">
                    </td>
                </tr>
                <tr>
                    <td><label for="txtLinks">Links</label></td>
                    <td>
                        <textarea name="links" id="txtLinks" style="width: 370px; height: 220px;">${fn:escapeXml(linkCollection.links)}</textarea>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td><input name="submit" type="submit" value="Save"></td>
                </tr>
            </table>
            <a href="${homeUrl}">Back</a>
        </form>
    </c:otherwise>
</c:choose>

<%@include file="../viewPartials/footer.jsp" %>